package com.hongdee.crm.kpi.controller;


import com.hongdee.base.entity.ResultEntity;
import com.hongdee.crm.kpi.service.IRealMaintainBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 实际保养回厂率统计报表
 * Created by zhangkai on 2017/7/22.
 */
@RestController
@RequestMapping("/crm/kpi")
public class RealMaintainBackController {

    @Autowired
    private IRealMaintainBackService iRealMaintainBackService;

    /**
     * 基盘保养回站率-二保保养回站
     * 在基盘月内进行过保养的车辆在，指定的时期内进行回厂保养的车辆数
     *
     * @param uid
     * @param token
     * @param baseMon 基盘月
     * @param mDate   考核期
     * @return
     * @throws Exception
     */
    @RequestMapping("/realByBack")
    @ResponseBody
    public Map realBack(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "baseMon", defaultValue = "") String baseMon,
                        @RequestParam(name = "mDate", defaultValue = "") String mDate,
                        @RequestParam(name = "companyId", defaultValue = "") String companyId

    ) throws Exception {
        if (StringUtils.isEmpty(companyId)) {
            throw new Exception("请选择公司！");
        }
        List resList = iRealMaintainBackService.byBack(uid,baseMon, mDate, companyId);
        Map map = new HashMap<>();
        map.put("dataList", resList);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     *
     * 基盘保养回店率-定保明细
     * 定保回站率明细
     * @param uid
     * @param token
     * @param baseMon
     * @param mDate
     * @param type
     * @param id
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/realByBackDetail")
    @ResponseBody
    public Map realByBackDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                                @RequestParam(name = "token", defaultValue = "") String token,
                                @RequestParam(name = "baseMon", defaultValue = "") String baseMon,
                                @RequestParam(name = "mDate", defaultValue = "") String mDate,
                                @RequestParam(name = "type", defaultValue = "") String type,
                                @RequestParam(name = "id", defaultValue = "") String id,
                                @RequestParam(name = "start", defaultValue = "0") String start,
                                @RequestParam(name = "limit", defaultValue = "50") String limit,
                                @RequestParam(name = "companyId", defaultValue = "") String companyId

    ) throws Exception {
        Map resList = iRealMaintainBackService.byBackDetail(companyId,baseMon, mDate, uid, id, type, start, limit);
        resList.put("success", true);
        resList.put("msg", "查询成功!!");
        return resList;
    }

    /**
     * 基盘保养回站率-首保
     * 基盘月时间按销售日期
     * 考核期指定回厂的截止日期，默认为当天，在期间内回厂首保的统计
     * 首保回站率
     *
     * @param uid
     * @param token
     * @param baseMon
     * @param mDate
     * @return
     * @throws Exception
     */
    @RequestMapping("/sbByBack")
    @ResponseBody
    public Map sbBack(@RequestParam(name = "uid", defaultValue = "") String uid,
                      @RequestParam(name = "token", defaultValue = "") String token,
                      @RequestParam(name = "baseMon", defaultValue = "") String baseMon,
                      @RequestParam(name = "mDate", defaultValue = "") String mDate,
                      @RequestParam(name = "companyId", defaultValue = "") String companyId
    ) throws Exception {
        if (StringUtils.isEmpty(companyId)) {
            throw new Exception("请选择公司！");
        }
        List resList = iRealMaintainBackService.sbBack(baseMon, mDate, companyId);
        Map map = new HashMap<>();
        map.put("dataList", resList);
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * 首保回站率-基盘客户明细
     * 基盘月时间按销售日期
     * 考核期指定回厂的截止日期，默认为当天，在期间内回厂首保的统计
     * 首保回站明细
     *
     * @param uid
     * @param token
     * @param baseMon
     * @param mDate
     * @param type
     * @param id
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/sbByBackDetail")
    @ResponseBody
    public Map sbBackDetail(@RequestParam(name = "uid", defaultValue = "") String uid,
                            @RequestParam(name = "token", defaultValue = "") String token,
                            @RequestParam(name = "baseMon", defaultValue = "") String baseMon,
                            @RequestParam(name = "mDate", defaultValue = "") String mDate,
                            @RequestParam(name = "type", defaultValue = "") String type,
                            @RequestParam(name = "id", defaultValue = "") String id,
                            @RequestParam(name = "start", defaultValue = "0") String start,
                            @RequestParam(name = "limit", defaultValue = "50") String limit,
                            @RequestParam(name = "companyId", defaultValue = "") String companyId
    ) throws Exception {
        if (StringUtils.isEmpty(companyId)) {
            throw new Exception("请选择公司！");
        }
        Map resList = iRealMaintainBackService.sbBackDetail(baseMon, mDate, companyId, id, type, start, limit);
        resList.put("success", true);
        resList.put("msg", "查询成功!!");
        return resList;
    }
}
